//
//  LSZIndividualRankingViewController.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/9/2.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZIndividualRankingViewController.h"

@interface LSZIndividualRankingViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong) UITableView * tableViewIndividualRanking;
@property(nonatomic,strong) LSZIndividualRankingManager * individualRankingManager;
@end

@implementation LSZIndividualRankingViewController
-(void)intWithIndividualRanking
{
    [LSZRequestDicData initWithIndividualRanking:^(BOOL isOk, NSString * string, LSZIndividualRankingManager * manager) {
        if (isOk == YES) {
            self.individualRankingManager = manager;
            [self.tableViewIndividualRanking reloadData];
        }else{
            if ([string isEqualToString:@"重复登录"]) {
                [LSZPublicClassDataToll RepeatLoginInterfaceJump:self.view fromVC:@"LSZIndividualRankingViewController"];
            }else{
                [LSZPublicClassDataToll initWithAlertKuangView:self.view string:string];
            }
        }
    }];
}
-(void)goToLogin
{
    [LSZPublicClassDataToll goToLogin];
}
-(void)addNotificationCenter
{
    NSString * strDelete = [NSString stringWithFormat:@"%@Login",@"LSZIndividualRankingViewController"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToLogin) name:strDelete object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self addNotificationCenter];
    [self intWithIndividualRanking];
    [self.tableViewIndividualRanking registerClass:[LSZNameDepartmentTableViewCell class] forCellReuseIdentifier:@"LSZNameDepartmentTableViewCell"];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.individualRankingManager.arrayData.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 20;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZNameDepartmentTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZNameDepartmentTableViewCell" forIndexPath:indexPath];
    cell.labelNumber.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row+1];
       LSZIndividualRankingMg * mg = nil;
    mg = self.individualRankingManager.arrayData[indexPath.row];
    cell.labelName.text = mg.customerName;
    cell.labelDepartment.text = mg.branchName;
    if (indexPath.row < 3) {
        cell.imageViewIcon.hidden = NO;
        if(indexPath.row == 0 ){
            cell.imageViewIcon.image = [UIImage imageNamed:@"第一名"];
        }else if (indexPath.row == 1){
            cell.imageViewIcon.image = [UIImage imageNamed:@"第二名"];
        }
        else{
            cell.imageViewIcon.image = [UIImage imageNamed:@"第三名"];
        }
    }else{
        cell.imageViewIcon.hidden = YES;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(UITableView *)tableViewIndividualRanking
{
    if (_tableViewIndividualRanking == nil) {
        _tableViewIndividualRanking = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-44-40) style:UITableViewStyleGrouped];
        _tableViewIndividualRanking.delegate = self;
        _tableViewIndividualRanking.dataSource = self;
        _tableViewIndividualRanking.estimatedRowHeight=0;
        _tableViewIndividualRanking.estimatedSectionFooterHeight =0;
        _tableViewIndividualRanking.estimatedSectionHeaderHeight =0;
        [_tableViewIndividualRanking setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
        [self.view addSubview:_tableViewIndividualRanking];
    }
    return _tableViewIndividualRanking;
}
@end
